// ml:run = $bin < input
#include <iostream>

using ll = long long;
ll a, b, n, l, t, m;

ll sum(ll r)
{
    ll v = a * r + (r * (r - 1) / 2) * b;
    ll u = a * (l - 1) + ((l - 1) * (l - 2) / 2) * b;
    return v - u;
}

bool judge(ll mid)
{
    return sum(mid) <= t * m && a + (mid - 1) * b <= t;
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    std::cin >> a >> b >> n;
    for (int i = 0; i < n; i++) {
        std::cin >> l >> t >> m;
        if (sum(l) > t) { std::cout << "-1\n"; continue; }
        ll tl = l, tr = l + t;
        while (tl + 1 < tr) {
            ll mid = (tl + tr) / 2;
            if (judge(mid)) tl = mid;
            else tr = mid;
        }
        if (judge(tr)) tl = tr;
        std::cout << tl << "\n";
    }
}

